﻿using GoogleAds;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using TruyenCuoi.Entity;
using VideoCookBook.Entity;

namespace TruyenCuoi.ViewModel
{
    public class DetailStoryViewModel : BindableBase
    {
        public static ReturnStory Detail;

        private string title;
        private string content;
        private string copyRight;
        private string urlSong;
        private InterstitialAd interstitialAd;
        public string UrlSong
        {
            get { return urlSong; }
            set { SetProperty(ref urlSong, value); }
        }

        public string CopyRight
        {
            get { return copyRight; }
            set { SetProperty(ref copyRight, value); }
        }
        public string Content
        {
            get { return content; }
            set { SetProperty(ref content, value); }
        }


        public string Title
        {
            get { return title; }
            set { SetProperty(ref title, value); }
        }
        public DetailStoryViewModel()
        {
            if (Detail != null)
            {
                Title = Detail.StoryName;
                Content = Detail.StoryContent.Trim();
                if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
                    DetailPage_Loaded();
            }
        }
        void DetailPage_Loaded()
        {
            // NOTE: Edit "MY_AD_UNIT_ID" with your interstitial
            // ad unit id.
            interstitialAd = new InterstitialAd("ca-app-pub-9326203813534864/1018645637");
            // NOTE: You can edit the event handler to do something custom here. Once the
            // interstitial is received it can be shown whenever you want.
            interstitialAd.ReceivedAd += OnAdReceived;
            interstitialAd.FailedToReceiveAd += OnFailedToReceiveAd;
            AdRequest adRequest = new AdRequest();
            adRequest.ForceTesting = false;
            interstitialAd.LoadAd(adRequest);
            Thread.Sleep(2000);
        }

        private void OnAdReceived(object sender, AdEventArgs e)
        {
            interstitialAd.ShowAd();
        }

        private void OnFailedToReceiveAd(object sender, AdErrorEventArgs e)
        {
            MessageBox.Show("Some thing went wrong!");
        }
    }
}
